/**
 * 
 */
package cn.haona.game.simb.wap.servlet.init;

import java.io.IOException;

import javax.servlet.ServletConfig;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import cn.haona.game.simb.wap.servlet.WebDefine;

/**
 * @author Administrator
 * 
 */
public class AutoStartInitServlet extends HttpServlet {

	private String name;
	private String value;
	// 初始化的文件
	private String initFileName;

	public AutoStartInitServlet() {
		// TODO Auto-generated constructor stub
	}

	@Override
	public void init() throws ServletException {
		super.init();
		

		
		ServletConfig config = getServletConfig();
		
		//真实路径
		String realPath=config.getServletContext().getRealPath("/");
//		System.out.println("RealPath="+realPath);
		//设置真实路径
		WebDefine.WEB_APP_REAL_PATH=realPath;
		
		//参数
		if (config.getInitParameter("name") != null) {
			name = config.getInitParameter("name");
		}
		if (config.getInitParameter("value") != null) {
			value = config.getInitParameter("value");
		}
		if (config.getInitParameter("initFileName") != null) {
			initFileName = config.getInitParameter("initFileName");
		}
		
		//建立一个初始化工程的实例
		InitWebProject iwp=InitWebProject.getInstance();
		iwp.initMe(realPath+initFileName);
		// ServletContext context = getServletContext();
		// context.setAttribute("companyName", companyName);
//		System.out.println("随服务启动了.name=" + name + ";value=" + value);
	}


//	@Override
//	protected void doGet(HttpServletRequest req, HttpServletResponse resp)
//			throws ServletException, IOException {
//		// TODO Auto-generated method stub
//		doRequest(req, resp);
//	}
//
//	@Override
//	protected void doPost(HttpServletRequest req, HttpServletResponse resp)
//			throws ServletException, IOException {
//		// TODO Auto-generated method stub
//		doRequest(req, resp);
//	}
//
//	private void doRequest(HttpServletRequest req, HttpServletResponse resp) {
//		initWebAppRoot(req, resp);
//	}
//
//	private void initWebAppRoot(HttpServletRequest req, HttpServletResponse resp) {
//		String path = req.getScheme() + "://" + req.getServerName() + ":"
//				+ req.getServerPort() + req.getContextPath();
//		WebDefine.WEB_APP_ROOT=path;
//		System.out.println("初始化的path="+WebDefine.WEB_APP_ROOT);
//	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getValue() {
		return value;
	}

	public void setValue(String value) {
		this.value = value;
	}

}
